from collections import Counter
from fractions import Fraction
from typing import List


class Solution:
    def interchangeableRectangles(self, rectangles: List[List[int]]) -> int:
        count = Counter(Fraction(width, height) for width, height in rectangles)
        ans = 0
        for num in count.values():
            ans += num * (num - 1) // 2
        return ans


if __name__ == "__main__":
    print(Solution().interchangeableRectangles(rectangles=[[4, 8], [3, 6], [10, 20], [15, 30]]))  # 6
    print(Solution().interchangeableRectangles(rectangles=[[4, 5], [7, 8]]))  # 0
